var plugin = requirePlugin("WechatSI")
let manager = plugin.getRecordRecognitionManager()

let innerAudioContext = null;

let auidoSrc = ""

let init =  ()=> {
  innerAudioContext = wx.createInnerAudioContext();
  innerAudioContext.onError(function (res) {
    wx.showToast({
      title: '语音播放初始化失败',
    })
  })
}

//阅读文字
let readText =  (content)=> {
  plugin.textToSpeech({
    lang: "zh_CN",
    tts: true,
    content: content,
    success: function (res) {
      auidoSrc = res.filename;
      readStart();
    },
    fail: function (res) {
      wx.showToast({
        title: '语音转换失败',
      })
    }
  })
}
//开始阅读文字
let readStart =  ()=> {
  innerAudioContext.src = auidoSrc //设置音频地址
  innerAudioContext.play(); //播放音频
}

module.exports = {
  innerAudioContext:{
    init,
    readText
  },
}